package com.powernode.ssm.pojo.bo;

import com.alibaba.excel.metadata.Head;
import com.powernode.ssm.utils.SpringUtils;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.File;
import java.util.List;

// ===== 根类，对应 <root> =====
@XmlRootElement(name = "root")
public class XmlToObjectAllInOne {

    private Head head;
    private Body body;

    @XmlElement(name = "head")
    public Head getHead() {
        return head;
    }

    public void setHead(Head head) {
        this.head = head;
    }

    @XmlElement(name = "body")
    public Body getBody() {
        return body;
    }

    public void setBody(Body body) {
        this.body = body;
    }

    // ===== 内部类：Head，对应 <head> =====
    public static class Head {

        private String reqflag;
        private String msgtype;
        private String tr_code;
        private String corp_no;
        private String oreq_no;
        private String tr_acdt;
        private String tr_time;
        private String ans_code;
        private String ans_info;
        private String reserved;

        @XmlElement(name = "reqflag")
        public String getReqflag() {
            return reqflag;
        }

        public void setReqflag(String reqflag) {
            this.reqflag = reqflag;
        }

        @XmlElement(name = "msgtype")
        public String getMsgtype() {
            return msgtype;
        }

        public void setMsgtype(String msgtype) {
            this.msgtype = msgtype;
        }

        @XmlElement(name = "tr_code")
        public String getTr_code() {
            return tr_code;
        }

        public void setTr_code(String tr_code) {
            this.tr_code = tr_code;
        }

        @XmlElement(name = "corp_no")
        public String getCorp_no() {
            return corp_no;
        }

        public void setCorp_no(String corp_no) {
            this.corp_no = corp_no;
        }

        @XmlElement(name = "oreq_no")
        public String getOreq_no() {
            return oreq_no;
        }

        public void setOreq_no(String oreq_no) {
            this.oreq_no = oreq_no;
        }

        @XmlElement(name = "tr_acdt")
        public String getTr_acdt() {
            return tr_acdt;
        }

        public void setTr_acdt(String tr_acdt) {
            this.tr_acdt = tr_acdt;
        }

        @XmlElement(name = "tr_time")
        public String getTr_time() {
            return tr_time;
        }

        public void setTr_time(String tr_time) {
            this.tr_time = tr_time;
        }

        @XmlElement(name = "ans_code")
        public String getAns_code() {
            return ans_code;
        }

        public void setAns_code(String ans_code) {
            this.ans_code = ans_code;
        }

        @XmlElement(name = "ans_info")
        public String getAns_info() {
            return ans_info;
        }

        public void setAns_info(String ans_info) {
            this.ans_info = ans_info;
        }

        @XmlElement(name = "reserved")
        public String getReserved() {
            return reserved;
        }

        public void setReserved(String reserved) {
            this.reserved = reserved;
        }
    }

    // ===== 内部类：Body，对应 <body> =====
    public static class Body {

        private String ratingcode;
        private String certiftype;
        private String certinum;
        private String accname;
        private String trandate;
        private String appronum;
        private String modleid;
        private String sunrecord;
        private String level;

        private Details details;

        @XmlElement(name = "ratingcode")
        public String getRatingcode() {
            return ratingcode;
        }

        public void setRatingcode(String ratingcode) {
            this.ratingcode = ratingcode;
        }

        @XmlElement(name = "certiftype")
        public String getCertiftype() {
            return certiftype;
        }

        public void setCertiftype(String certiftype) {
            this.certiftype = certiftype;
        }

        @XmlElement(name = "certinum")
        public String getCertinum() {
            return certinum;
        }

        public void setCertinum(String certinum) {
            this.certinum = certinum;
        }

        @XmlElement(name = "accname")
        public String getAccname() {
            return accname;
        }

        public void setAccname(String accname) {
            this.accname = accname;
        }

        @XmlElement(name = "trandate")
        public String getTrandate() {
            return trandate;
        }

        public void setTrandate(String trandate) {
            this.trandate = trandate;
        }

        @XmlElement(name = "appronum")
        public String getAppronum() {
            return appronum;
        }

        public void setAppronum(String appronum) {
            this.appronum = appronum;
        }

        @XmlElement(name = "modleid")
        public String getModleid() {
            return modleid;
        }

        public void setModleid(String modleid) {
            this.modleid = modleid;
        }

        @XmlElement(name = "sunrecord")
        public String getSunrecord() {
            return sunrecord;
        }

        public void setSunrecord(String sunrecord) {
            this.sunrecord = sunrecord;
        }

        @XmlElement(name = "level")
        public String getLevel() {
            return level;
        }

        public void setLevel(String level) {
            this.level = level;
        }

        @XmlElement(name = "details")
        public Details getDetails() {
            return details;
        }

        public void setDetails(Details details) {
            this.details = details;
        }
    }

    // ===== 内部类：Details，对应 <details> =====
    public static class Details {

        private List<Detail> detail;

        @XmlElement(name = "detail")
        public List<Detail> getDetail() {
            return detail;
        }

        public void setDetail(List<Detail> detail) {
            this.detail = detail;
        }
    }

    // ===== 内部类：Detail，对应 <detail> =====
    public static class Detail {

        private String gradeitem;
        private String gradevalue;

        @XmlElement(name = "gradeitem")
        public String getGradeitem() {
            return gradeitem;
        }

        public void setGradeitem(String gradeitem) {
            this.gradeitem = gradeitem;
        }

        @XmlElement(name = "gradevalue")
        public String getGradevalue() {
            return gradevalue;
        }

        public void setGradevalue(String gradevalue) {
            this.gradevalue = gradevalue;
        }
    }

    // ===== main 方法：JAXB 解析入口 =====
    public static void main(String[] args) {

        String xmlPath = "D:\\linyucong\\javaCode\\SpringBoot3-PN\\ssm\\src\\main\\resources\\xml\\a1.xml";
        XmlToObjectAllInOne rootObj = new SpringUtils().convertDocument2Obj(xmlPath, XmlToObjectAllInOne.class);
        System.out.println("===== Head 信息 =====");
        System.out.println("reqflag: " + rootObj.getHead().getReqflag());
        System.out.println("tr_code: " + rootObj.getHead().getTr_code());
        System.out.println("ans_code: " + rootObj.getHead().getAns_code());
        System.out.println("ans_info: " + rootObj.getHead().getAns_info());

        System.out.println("\n===== Body 信息 =====");
        System.out.println("ratingcode: " + rootObj.getBody().getRatingcode());
        System.out.println("accname: " + rootObj.getBody().getAccname());
        System.out.println("level: " + rootObj.getBody().getLevel());

        System.out.println("\n===== Details 信息 =====");
        rootObj.getBody().getDetails().getDetail().forEach(d -> {
            System.out.println("  GradeItem: " + d.getGradeitem() + ", Value: " + d.getGradevalue());
        });


    }
}
